home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / lib / partman / init.d / 30parted < prev    next >
Text File  |  2008-10-29  |  3KB  |  141 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. . /lib/partman/lib/base.sh
  6. . /usr/share/debconf/confmodule
  7.  
  8. ORIG_IFS="$IFS"
  9.  
  10. part_of_sataraid () {
  11.     local raiddev
  12.     for raiddev in $(dmraid -r -c); do
  13.         if [ "$(readlink -f $raiddev)" = $1 ]; then
  14.             return 0
  15.         fi
  16.     done
  17.     return 1
  18. }
  19.  
  20. part_of_multipath() {
  21.     local mpdev
  22.     type multipath >/dev/null 2>&1 || return 1
  23.  
  24.     if is_multipath_part $1; then
  25.         return 0
  26.     fi
  27.     # The block devices that make up the multipath:
  28.     # Output looks like \_ 4:0:0:1 sdc 8:32 ...
  29.     for mpdev in $(multipath -l | \
  30.                grep '_ \([#0-9]\+:\)\{3\}[#0-9]\+ [hs]d[a-z]\+ [0-9]\+:[0-9]\+' | \
  31.                cut -f4 -d' '); do
  32.         if [ "$(readlink -f /dev/$mpdev)" = $1 ]; then
  33.             return 0
  34.         fi
  35.     done
  36.     return 1
  37. }
  38.  
  39. if [ ! -f /var/run/parted_server.pid ]; then
  40.     mkdir -p /var/run
  41.     parted_server
  42.     RET=$?
  43.     if [ $RET != 0 ]; then
  44.         # TODO: How do we signal we couldn't start parted_server properly?
  45.         exit $RET
  46.     fi
  47.  
  48.     rm -rf /var/lib/partman/old_devices
  49.     if [ -d $DEVICES ]; then
  50.         mv $DEVICES /var/lib/partman/old_devices
  51.     fi
  52.     mkdir $DEVICES || true
  53.  
  54.     # Exclude devices that have mounted partitions.
  55.     disks=
  56.     db_get partman/filter_mounted
  57.     if [ "$RET" != false ]; then
  58.         while read dev rest; do
  59.             # Taken from split_device() in grub-installer.
  60.             disk=
  61.             case $dev in
  62.                 /dev/[vhs]d[a-z]*)
  63.                     disk="$(echo "$dev" | sed 's,\(/dev/[a-z]\+\).*,\1,')"
  64.                 ;;
  65.                 /dev/*/c*d*)
  66.                     disk="$(echo "$dev" | sed 's,\(/dev/.*/c[0-9]\+d[0-9]\+\).*,\1,')"
  67.                 ;;
  68.             esac
  69.                     if [ -z "$disk" ]; then
  70.                 continue
  71.             fi
  72.             if [ -n "$disks" ]; then
  73.                 disks="$disks\|$disk"
  74.             else
  75.                 disks="$disk"
  76.             fi
  77.         done < /proc/mounts
  78.         fi
  79.     if [ "$disks" ]; then
  80.         disks="^\($disks\)"
  81.     else
  82.         disks="^$"
  83.     fi
  84.     IFS="$NL"
  85.     for partdev in $(parted_devices |
  86.         grep -v '^/dev/md' | grep -v "$disks" |
  87.         sed 's,^/dev/\(ide\|scsi\|[hs]d\),!/dev/\1,' |
  88.         sort |
  89.         sed 's,^!,,' ); do
  90.  
  91.         IFS="$TAB"
  92.         set -- $partdev
  93.         IFS="$ORIG_IFS"
  94.  
  95.         device=$1
  96.         size=$2
  97.         model=$3
  98.  
  99.         # Skip devices that are part of a dmraid device
  100.         if type dmraid >/dev/null 2>&1; then
  101.             if part_of_sataraid $device && \
  102.                [ -f /var/lib/disk-detect/activate_dmraid ]; then
  103.                 continue
  104.             fi
  105.         fi
  106.  
  107.         # Skip devices that are part of a multipathed device
  108.         if part_of_multipath $device; then
  109.             continue
  110.         fi
  111.  
  112.         dirname=$(echo $device | sed 's:/:=:g')
  113.         dev=$DEVICES/$dirname
  114.         if [ -d /var/lib/partman/old_devices/$dirname ]; then
  115.             mv /var/lib/partman/old_devices/$dirname $dev
  116.         else
  117.             mkdir $dev || continue
  118.         fi
  119.         printf "%s" "$device" >$dev/device
  120.         printf "%s" "$size" >$dev/size
  121.         printf "%s" "$model" >$dev/model
  122.  
  123.         if type dmraid >/dev/null 2>&1; then
  124.             if dmraid -sa -c | grep $(basename $device); then
  125.                 >$dev/sataraid
  126.             fi
  127.         fi
  128.  
  129.         cd $dev
  130.         open_dialog OPEN "$(cat $dev/device)"
  131.         read_line response
  132.         close_dialog
  133.         if [ "$response" = failed ]; then
  134.             cd /
  135.             rm -rf $dev
  136.         fi
  137.     done
  138.  
  139.     rm -rf /var/lib/partman/old_devices
  140. fi
  141.